/**
 * 
 */
package gpl.scotlandyard.fugitive.hint;

import gpl.androidcommons.app.NApplication;
import gpl.scotlandyard.utils.Config;
import gpl.scotlandyard.utils.Scotlandyard;

import java.io.IOException;
import java.io.InputStream;
import java.util.prefs.InvalidPreferencesFormatException;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Application;
import android.content.res.AssetManager;
import android.util.Log;

/** @author norbert */
public class ApplicationManager extends NApplication {

  private static final String TAG = Application.class.toString();

  @Override
  public void onCreate() {
    super.onCreate();
  }

  public static void loadConfig(Activity activity) {
    try {
      InputStream confStream = activity.getAssets().open(Scotlandyard.Config.CONFIGURATION_FILE, AssetManager.ACCESS_BUFFER);
      Config.load(confStream);
    } catch (IOException e) {
      Log.e(TAG, "impossible to load configuration : " + e.getLocalizedMessage());
      new AlertDialog.Builder(activity).setMessage(R.string.error_load_map).create().show();
      Log.e(TAG, "stop application");
      activity.finish();
    } catch (InvalidPreferencesFormatException e) {
      Log.e(TAG, "impossible to load configuration : " + e.getLocalizedMessage());

      new AlertDialog.Builder(activity).setMessage(R.string.error_load_map).create().show();
      Log.e(TAG, "stop application");
      activity.finish();
    }
  }

}
